/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Utility;

import java.io.*;

/**
 *
 * @author Hmong
 */
public class StringUtility {

    public static String Byte2String(byte[] b, int offset, int len) {
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(b, offset, len);
            DataInputStream inputstream = new DataInputStream(bais);
            return inputstream.readUTF();
        } catch (IOException e) {
            return null;
        }
    }

    public static byte[] String2Byte(String s) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream outputstream = new DataOutputStream(baos);
            outputstream.writeUTF(s);
            return baos.toByteArray();
        } catch (IOException e) {
            return null;
        }
    }
}
